package tb;

import org.bytedeco.javacv.*;
import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.highgui.HighGui;
import org.opencv.imgproc.Imgproc;
import org.opencv.videoio.VideoCapture;

import javax.swing.*;
import java.util.EnumSet;

public class JavaCVTest {
    public static void main(String[] args) {
        JavaCVTest test = new JavaCVTest();
        test.testRtsp();
    }

    public void testRtsp() {
        //必须要加入这两个东西
//        System.load("D:\\Programs\\opencv\\build\\x64\\vc15\\bin\\opencv_world3410.dll");
//        System.load("D:\\Programs\\opencv\\build\\bin\\opencv_ffmpeg3410_64.dll");
        VideoCapture vc = new VideoCapture();
        boolean isOpen = vc.open("rtsp://admin:123456789a@192.168.31.66:554/h264/ch1/main/av_stream");

        System.out.println("isOpen="+isOpen);

        Mat mat = new Mat();
        String winName = "showFrame";
        int height = 2160,width = 3840;
        HighGui.namedWindow(winName);
        HighGui.resizeWindow(winName, width, height);
        while(vc.read(mat)){
            System.out.println("read.......");
            // 重置大小
            Mat dst = new Mat();
            Imgproc.resize(mat, dst, new Size(width,height));
            // 显示
            HighGui.imshow(winName, dst);
            // waitkey 必须要，否则无法显示
            int key = HighGui.waitKey(1);
            System.out.println("key="+key);
            //esc键退出
            if(key == 27){
                break;
            }
            //拿到了每帧之后要干嘛就是后面逻辑的事情了
        }
        HighGui.destroyAllWindows();
        vc.release();
    }
}